/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.university.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.thinkgem.jeesite.common.service.TreeService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.sys.entity.Office;
import com.thinkgem.jeesite.modules.university.dao.UniversityOrgDao;
import com.thinkgem.jeesite.modules.university.entity.UniversityOrg;
import com.thinkgem.jeesite.modules.university.utils.UniversityOrgUtils;

/**
 * 组织机构Service
 * @author 朱俊吉
 * @version 2017-12-16
 */
@Service
@Transactional(readOnly = true)
public class UniversityOrgService extends TreeService<UniversityOrgDao, UniversityOrg> {

	@Autowired
	public UniversityOrg get(String id) {
		return super.get(id);
	}
	
	public List<UniversityOrg> findAllList() {
			return dao.findAllList(new UniversityOrg());
	}
	
	public List<UniversityOrg> findByParentIdsLike(UniversityOrg universityOrg) {
		if(universityOrg != null){
			universityOrg.setParentIds(universityOrg.getParentIds()+"%");
			return dao.findByParentIdsLike(universityOrg);
		}
		return  new ArrayList<UniversityOrg>();
	}
	
	public List<UniversityOrg> findList(UniversityOrg universityOrg) {
		return super.findList(universityOrg);
	}
	
	@Transactional(readOnly = false)
	public void save(UniversityOrg universityOrg) {
		super.save(universityOrg);
	}
	
	@Transactional(readOnly = false)
	public void delete(UniversityOrg universityOrg) {
		super.delete(universityOrg);
	}

	public UniversityOrg getByName(String name) {
		return dao.getByName(new UniversityOrg("",name));
	}

	public List<UniversityOrg> findByCodeLike(UniversityOrg universityOrg) {
		if(universityOrg == null){
			universityOrg = new UniversityOrg();
		}
		if(universityOrg != null && StringUtils.isBlank(universityOrg.getCode())){
			universityOrg.setCode(UniversityOrgUtils.TOP_NODE_CODE);
		}
		return dao.findByCodeLike(universityOrg);
	}
	
}